<template>
  <view class="box">
       <scroll-view
      class="main"
      @scrolltolower="loadMore"
      scroll-y
    >
    <uni-search-bar
      class="uni-mt-10"
      radius="100"
      placeholder="搜索人名、内容"
      clearButton="none"
      cancelButton="none"
      @confirm="search"
    >
    </uni-search-bar>
    <view class="apply">
      <view
        @click="clickDetail(item)"
        v-for="(item, index) in data"
        :key="index"
        class="apply_box"
      >
        <view class="apply_zhong">
          <text
            >{{ item.startUsername }}的{{ item.processDefinitionName }}</text
          >
          <text
            v-if="item.processIsFinished === 'reject'"
            class="apply_zhong_bs"
            >{{ statusbar(item.processIsFinished) }}</text
          >
          <text v-else class="apply_zhong_bt">{{
            statusbar(item.processIsFinished)
          }}</text>
          <text style="color: #b2aaaa; font-size: 12px">{{
            item.createTime
          }}</text>
        </view>
        <view class="apply_bottom">
          <view>申请理由：{{ item.variables.approveReason?item.variables.approveReason: item.variables.useReason}} </view>
          <view
            v-if="item.processIsFinished === 'reject'"
            style="color: #e24959; margin: 10px 0 0 0"
          >
            驳回原因：{{ fullMessage(item) }}
          </view>
          <u-button v-if="item.processIsFinished === 'reject'" class="cxedit">
            重新修改
          </u-button>
        </view>
      </view>
    </view>
    </scroll-view>
  </view>
</template>

<script>
import { sendList } from "@/api/index";

export default {
  name: "MinirabbitApplication",

  data() {
    return {
      data: [],
      size:8,
      loding:false,
      status: [
        {
          label: "进行中",
          value: "unfinished",
        },
        {
          label: "已完成",
          value: "finished",
        },
        {
          label: "已终结",
          value: "terminate",
        },
        {
          label: "已撤销",
          value: "withdraw",
        },
        {
          label: "已撤回",
          value: "recall",
        },
        {
          label: "被驳回",
          value: "reject",
        },
        {
          label: "已删除",
          value: "deleted",
        },
      ],
    };
  },
   created() {
  this.getList()
   
  },
  mounted() {},

  methods: {
   async getList(){
        // 列表详情
    const res = await sendList({
      size: this.size,
    });
    this.data = res.data.records;
    if (res.data.total>this.size) {
      this.loding=true
    }else{
       this.loding=false
    }
    },
   async loadMore(){
      console.log('触底了');
      if (this.loding) {
      this.size=this.size+10
         this.getList()
      }
    },
    clickDetail(item) {
      if (item.processIsFinished !== "reject") {
        if (item.processDefinitionKey === "office-article") {
          //发文申请详情
          uni.navigateTo({
            url: `/pages/cardetail/dispatchdetail?row=${JSON.stringify(
              item
            )}&type=1`,
          });
        } else if (item.processDefinitionKey === "office-seal") {
          // 用章申请详情
          uni.navigateTo({
            url: `/pages/cardetail/chaptersdetail?row=${JSON.stringify(
              item
            )}&type=1`,
          });
        } else if (item.processDefinitionKey === "office-car") {
          //用车申请详情
          uni.navigateTo({
            url: `/pages/cardetail/index?row=${JSON.stringify(item)}&type=1`,
          });
        }
      } else {
        //驳回重新修改
        if (item.processDefinitionKey === "office-article") {
          //发文申请详情
          uni.navigateTo({
            url: `/pages/dispatch/index?row=${JSON.stringify(item)}`,
          });
        } else if (item.processDefinitionKey === "office-seal") {
          // 用章申请详情
          uni.navigateTo({
            url: `/pages/chapters/index?row=${JSON.stringify(item)}`,
          });
        } else if (item.processDefinitionKey === "office-car") {
          //用车申请详情
          uni.navigateTo({
            url: `/pages/usecar/index?row=${JSON.stringify(item)}`,
          });
        }
      }
    },
    // 驳回原因
    fullMessage(item) {
      const res = item.comments.find((items) => {
        return items.type === "rollbackComment";
      });
      return res?.fullMessage;
    },
    search() {
    },
    statusbar(val) {
      return this.status.find((item) => item.value === val).label;
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  height: 100vh;
}
.main {
  overflow: hidden;
}
.apply {
  width: 100%;
  margin: 10px 0;
  background-color: #fff;
  .apply_top {
    display: flex;
    justify-content: space-between;
    width: 100%;
    height: 50px;
    padding: 12px;
  }
  .apply_box {
    .apply_zhong {
      margin-top: 12px;
      display: flex;
      justify-content: space-between;
      padding: 0 10px;
      .apply_zhong_bt {
        padding: 1px 5px;
        margin-left: 30px;
        color: #21bd49;
        border: 1px solid #21bd49;
        border-radius: 5px;
      }
      .apply_zhong_bs {
        padding: 1px 5px;
        margin-left: 30px;
        color: #e56031;
        border: 1px solid #e56031;
        border-radius: 5px;
      }
    }
    .apply_bottom {
      font-size: 13px;
      padding: 8px 10px 20px;
      border-bottom: 1px solid #dddddd;
      .cxedit {
        width: 20%;
        text-align: right;
        background-color: #169bd5;
        border-radius: 5px;
        color: #fff;
        padding: 10px 0;
        margin-left: 80%;
      }
    }
  }
}
</style>